import { _decorator, animation, Component, EventTarget, Input, instantiate, Node, Script, tween, v2, v3, Vec2 } from 'cc';
import { Bullet } from './Bullet';
const { ccclass, property } = _decorator;

@ccclass('BulletTrackingPanel')
export class BulletTrackingPanel extends Component {
    @property(Node)
    monster: Node;
    @property(Node)
    bullet: Node;
    @property(Node)
    viewNode: Node

    private monsterArr: Node[] = []
    protected onLoad(): void {
        window.game = {
            EventMgr: new EventTarget(),
        }
        //监听怪物进入
        game.EventMgr.on("monster.enter", this.createBullet, this)


       
    }

    protected onDestroy(): void {
        game.EventMgr.off("monster.enter", this.createBullet, this)
    }

    start() {
        this.createMonster()
    }

    //生成怪物
    createMonster() {
        setInterval(() => {
            let monster = instantiate(this.monster)
            monster.active = true
            monster.parent = this.viewNode
            this.monsterArr.push(monster)
        }, 500)

    }

    //可以攻击 创建子弹
    createBullet(monster: Node) {
        let bullet = instantiate(this.bullet)
        bullet.active = true
        bullet.parent = this.viewNode
        game.EventMgr.emit(`bullet.attack_${bullet.uuid}`, monster)
    }


    
    update(dt) {

    }
}



